package core;

import stage.Index;

import java.io.File;

public class JitRm {
    /**
     * Remove a file from stage & remove record from ./index
     * @param path
     * @throws Exception
     */
    public static void remove(String path) throws Exception {
        Index currentIndex = new Index(); // load index content into Index object
        int checkExist = currentIndex.inIndex(new File(path));
        if (checkExist == -1) { // file not exist in index
            System.out.println("fatal: '" + path + "' did not match any files");
        }
        else { // find matched file
            currentIndex.deleteItem(new File(path));
            currentIndex.writeIndex(); // save to file after change
            System.out.println("Successfully remove " + path + " from stage."); // optional
        }
    }

}
